<?php 
//session_start();
ob_start();
include_once('connection/connection.php');
include_once('header.php');
include_once('menu.php');
$formId=$_SESSION['formID'];
$arrHabSource = $_SESSION['arrSource'];
//echo $_POST['loccount'];
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<script language="Javascript" type="text/javascript" src="js/ajaxFunction_q2.js"></script>
<script language="javascript" type="text/javascript" src="js/validate2.js"></script>
<script language=javascript>
function show_NF(val,i)
{
	//for(i=1; i<=total; i++)
	//{ 
		if(val == "NOT FUNCTIONAL" )
		{
			document.getElementById('nf'+i).style.display = "block";
			document.getElementById('nonFuncDiv'+i).style.display = "none";
			var chks=document.getElementsByName('opration_status'+i);	
			for(var j=0; j<chks.length; j++)
			{
				if(chks[j].checked)
				{
					chks[j].checked=false;
				}
			}
			//document.getElementById('quality_status'+i).disabled=true;	
			var chks1=document.getElementsByName('quality_status'+i);	
			for(var k=0; k<chks1.length; k++)
			{
				if(chks1[k].checked)
				{
					chks1[k].checked=false;
				}
			}
			//document.getElementById('yield'+i).disabled=true;
			var chks2=document.getElementsByName('yield'+i);
				
			for(var n=0; n<chks2.length; n++)
			{
				if(chks2[n].checked)
				{
					chks2[n].checked=false;
				}
			}
			//document.getElementById('seasonal_flunctuation'+i).disabled=true;
			var chks3=document.getElementsByName('seasonal_flunctuation'+i);	
			for(var m=0; m<chks3.length; m++)
			{
				if(chks3[m].checked)
				{
					chks3[m].checked=false;
				}
			}
			document.getElementById('water_table_fluctuation_min'+i).disabled=true;
			document.getElementById('water_table_fluctuation_max'+i).disabled=true;
		}	
		else
		{
			document.getElementById('nf'+i).style.display = "none";
			var chks = document.getElementsByName('repairable_status'+i);
			//var hasChecked = false;
			for(var j=0; j<chks.length; j++)
			{
				if(chks[j].checked)
				{
					chks[j].checked=false;
				}
			}
			document.getElementById('remarks'+i).value="";
			document.getElementById('nonFuncDiv'+i).style.display = "block";
			document.getElementById('opration_status'+i).disabled=false;	
			document.getElementById('quality_status'+i).disabled=false;	
			document.getElementById('yield'+i).disabled=false;
			document.getElementById('seasonal_flunctuation'+i).disabled=false;
			document.getElementById('water_table_fluctuation_min'+i).disabled=false;
			document.getElementById('water_table_fluctuation_max'+i).disabled=false;
		}
}


function onload_NF()
{
	//for(i=1; i<=total; i++)
	//{ 
		var countloc=document.getElementById('loccount').value;
		for(var i=1;i<countloc;i++)
		{
		var arr=document.getElementsByName('function_status'+i);
		//alert(arr[0].value);
		if(arr[1].checked)
		{
			document.getElementById('nf'+i).style.display = "block";
			document.getElementById('nonFuncDiv'+i).style.display = "none";
			var chks=document.getElementsByName('opration_status'+i);	
			for(var j=0; j<chks.length; j++)
			{
				if(chks[j].checked)
				{
					chks[j].checked=false;
				}
			}
			//document.getElementById('quality_status'+i).disabled=true;	
			var chks1=document.getElementsByName('quality_status'+i);	
			for(var k=0; k<chks1.length; k++)
			{
				if(chks1[k].checked)
				{
					chks1[k].checked=false;
				}
			}
			//document.getElementById('yield'+i).disabled=true;
			var chks2=document.getElementsByName('yield'+i);	
			for(var l=0; l<chks2.length; l++)
			{
				if(chks2[l].checked)
				{
					chks2[l].checked=false;
				}
			}
			//document.getElementById('seasonal_flunctuation'+i).disabled=true;
			var chks3=document.getElementsByName('seasonal_flunctuation'+i);	
			for(var m=0; m<chks3.length; m++)
			{
				if(chks3[m].checked)
				{
					chks3[m].checked=false;
				}
			}
			document.getElementById('water_table_fluctuation_min'+i).disabled=true;
			document.getElementById('water_table_fluctuation_max'+i).disabled=true;
		}	
		else
		{
			document.getElementById('nf'+i).style.display = "none";
			var chks = document.getElementsByName('repairable_status'+i);
			//var hasChecked = false;
			for(var j=0; j<chks.length; j++)
			{
				if(chks[j].checked)
				{
					chks[j].checked=false;
				}
			}
			document.getElementById('remarks'+i).value="";
			document.getElementById('nonFuncDiv'+i).style.display = "block";
			document.getElementById('opration_status'+i).disabled=false;	
			document.getElementById('quality_status'+i).disabled=false;	
			document.getElementById('yield'+i).disabled=false;
			document.getElementById('seasonal_flunctuation'+i).disabled=false;
			document.getElementById('water_table_fluctuation_min'+i).disabled=false;
			document.getElementById('water_table_fluctuation_max'+i).disabled=false;
		}
		}
}
</script>
<title>Edit Handpump Scheme</title>
</head>
<body onLoad="onload_NF();">
<?php
if(isset($_POST['submit']))
{
		$qr1="Delete from tbl_dtls_q2_hp_status where q2_id=$formId";
		$res1=mysql_query($qr1);
		//$fclick = true;
		//$rows_num = $_SESSION['rows_num'];
		$q2_id = $_SESSION['q2_id'];
		//echo $q2_id;
		$sum = $_SESSION['sum'];
		//echo "<br>";
		$i=1;
		foreach($arrHabSource as $key=>$val)
		{
			for($j=1; $j<=$val; $j++)
			{
		//for($i=1; $i<=$sum; $i++)
		//{
			//$hcode='habitation_code'.$i;
			$hname='habitation_name'.$i;
			$type_mh_oh='type_mh_oh'.$i;
			$location='location'.$i;
			$function_status='function_status'.$i;
			$opration_status='opration_status'.$i;
			$quality_status='quality_status'.$i;
			$yield='yield'.$i;
			$seasonal_flunctuation='seasonal_flunctuation'.$i;
			$water_table_fluctuation_min='water_table_fluctuation_min'.$i;
			$water_table_fluctuation_max='water_table_fluctuation_max'.$i;
			$repairable_status='repairable_status'.$i;
			$remarks='remarks'.$i;
			//echo "<br>";
			//$hcode=$_POST[$hcode];
			$hname=$_POST[$hname];
			$type_mh_oh=$_POST[$type_mh_oh];
			$location=$_POST[$location];
			$function_status=$_POST[$function_status];
			$opration_status=$_POST[$opration_status];
			$quality_status=$_POST[$quality_status];
			$yield=$_POST[$yield];
			$seasonal_flunctuation=$_POST[$seasonal_flunctuation];
			$water_table_fluctuation_min=$_POST[$water_table_fluctuation_min];
			$water_table_fluctuation_max=$_POST[$water_table_fluctuation_max];
			$repairable_status=$_POST[$repairable_status];
			$remarks=$_POST[$remarks];
			
			
			
			$qr="INSERT INTO tbl_dtls_q2_hp_status(q2_id, habitation_name, type_mh_oh, location, functional_status, operational_status, quality_status, yield, seasonal_fluctuation, water_table_min, water_table_max, repairable_status, remark) VALUES ('$q2_id', '$hname', '$type_mh_oh', '$location', '$function_status', '$opration_status', '$quality_status', '$yield', '$seasonal_flunctuation', '$water_table_fluctuation_min', '$water_table_fluctuation_max', '$repairable_status', '$remarks')"; 
			
			$res=mysql_query($qr);
			//echo $res;
			$i++;
			}
		}	
	
			if($res)
			{
				header('Location: editquestionnaire2_3.php');
				//echo "<br> success insertion Page2";
				//echo $res;
				//echo $qr;
			}
			else
			{
				echo "query==". $qr;
				echo "Unsuccessfull";
				
			}
				
}		
//else
//{
	//$fclick = false;
	//$flag=0;
	//echo "failed";
//}		
?>
<div align="center">
<form action="" method="post" enctype="multipart/form-data" name="questionnaire2_2" id="questionnaire2_2" onSubmit="return validate2()">
	<table border="0"  id="table1" cellspacing="0" cellpadding="0" style="padding:10px;">
		<tr>
			<td width="950" height="25">
				<p align="center">
				<font face="Verdana" style="font-size: 10pt; font-weight: 700" color="#000000">
				Edit Handpump Scheme</font>
		  	</td>
		</tr>
		
		<tr>
			<td height="18">
				<p align="center">
				<font style="font-size: 8.5pt" face="Arial" color="#000000">Page 2</font></p>
			</td>
		</tr>
		
		<tr>
			<td background="images/title.gif" height="20"><font color="#ffffff">&nbsp;
				<span style="font-weight: 700">
				<font face="Arial" style="font-size: 8.5pt">7. Water Source Details</font></span></font>
			</td>
		</tr>
		<tr>
			<td>
				<table border="0" width="1300" id="table4" cellpadding="0" bgcolor="#EEEEEE">
					
					<tr>
						<td bgcolor="#CCCCCC" align="center" width="160" >
							<address>
				 			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Habitation Name</font></address></td>
					  <td bgcolor="#CCCCCC" align="center" width="54" >
							<address>
				 			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Type of MH/OH</font></address></td>
					  		<td bgcolor="#CCCCCC" align="center" width="84" >
							<address>
							<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">&nbsp;&nbsp;Location of HP</font></address>				      </td>
						<td colspan="2" bgcolor="#CCCCCC" align="center">
							<address>
				  			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Functional Status</font></address>						</td><td><table width="753">
				  			  <tr>
						<td colspan="2" bgcolor="#CCCCCC" align="center" rowspan="2">
							<address>
				  			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Operational status</font></address>						</td>
						<td colspan="2" bgcolor="#CCCCCC" align="center" rowspan="2">
							<address>
				  			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Quality Status</font></address></td>
						<td bgcolor="#CCCCCC" align="center" width="141" rowspan="2">
							<address>
				  			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Yield</font></address></td>
						<td bgcolor="#CCCCCC" align="center" width="148" rowspan="2">
							<address>
				  			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Seasonal Fluctuation s in yield</font></address></td>
						<td height="21" colspan="2" align="center" bgcolor="#CCCCCC">
							<address>
				  			<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Water Table Fluctuations (m)</font></address></td>
					</tr>
					<tr>
						<td width="116" height="16" align="center" bgcolor="#CCCCCC">
							<address>
		  			  <font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Min</font></address></td>
						<td bgcolor="#CCCCCC" align="center" width="135">
							<address>
		  			  <font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Max</font></address></td>
					</tr></table></td></tr>
					
					
					<?php
					//$hname=$_SESSION['arr_habit_name'];
					//print_r($hname);
					//$hcode=$_SESSION['arr_habit_code'];
					//$sum = $_SESSION['sum'];
					$i=1;
					//$j=1;
					$sql_status="select * from tbl_dtls_q2_hp_status where q2_id=$formId order by id";
						$query_status=mysql_query($sql_status);
						//$row_crit=mysql_fetch_array($query_crit);
						//echo $row_crit['critical_hname'];
 	 					//$m=1;
						while($row_status=mysql_fetch_array($query_status))
					//foreach($arrHabSource as $key=>$val)
					
					{
					//for($k=1; $k<=$val; $k++)
					//{
					?>
					<tr>
						<td width="160" align="center"><input type="text" name="habitation_name<?php echo $i;?>" id="habitation_name<?php echo $i;?>" value="<?php echo $row_status['habitation_name']; //$key;?>" size="20" class="txt4" readonly/>
						<!--<input type="text" name="habitation_code<?php //echo $i;?>" id="habitation_code<?php echo $i;?>" value="<?php //echo $hcode[$i]['code'];?>" size="20" class="txt4"/></td>-->
					    <td align="center" width="54"><input type="text" name="type_mh_oh<?php echo $i;?>" id="type_mh_oh<?php echo $i;?>" value="<?php echo $row_status['type_mh_oh']; ?>" size="2" class="txt_1" readonly/></td>
					    
						
						
						<td width="84" align="center">
		  			  <input type="text" name="location<?php echo $i;?>" id="location<?php echo $i;?>" size="20" class="txt5" value="<?php echo $row_status['location'];?>"></td>
						<td width="139" align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  <input type="radio" name="function_status<?php echo $i;?>" id="function_status<?php echo $i;?>" value="FUNCTIONAL"<?php echo($row_status['functional_status']=='FUNCTIONAL')?'checked':'';?> onClick="show_NF(this.value,<?php echo $i; ?>)">F</font>					  </td>
						<td width="112" align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  <input type="radio" name="function_status<?php echo $i;?>" id=	                            "function_status<?php echo $i;?>" value="NOT FUNCTIONAL"<?php echo($row_status['functional_status']=='NOT FUNCTIONAL')?'checked':'';?> onClick="show_NF(this.value,<?php echo $i; ?>)">NF</font>					  </td>
						<td width="750" align="center"><div name="nonFuncDiv<?php echo $i; ?>" id="nonFuncDiv<?php echo $i; ?>"><table width="750"><tr><td width="46" align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  <input type="radio" name="opration_status<?php echo $i;?>" id="opration_status<?php echo $i;?>" value="In Use"<?php echo($row_status['operational_status']=='In Use')?'checked':'';?> checked="checked">IU</font>					  </td>
						<td width="51" align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  <input type="radio" name="opration_status<?php echo $i;?>" id="opration_status<?php echo $i;?>" value="Out of Use"<?php echo($row_status['operational_status']=='Out of Use')?'checked':'';?> >OU</font>					  </td>
						<td width="36" align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  <input type="radio" name="quality_status<?php echo $i;?>" id="quality_status<?php echo $i;?>" value="Potable"<?php echo($row_status['quality_status']=='Potable')?'checked':'';?> >P</font>					  </td>
						<td width="46" align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  <input type="radio" name="quality_status<?php echo $i;?>" id="quality_status<?php echo $i;?>" value="Not Potable"<?php echo($row_status['quality_status']=='Not Potable')?'checked':'';?>>NP</font>					  </td>
						<td width="138">
							<p align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
							<input type="radio" name="yield<?php echo $i;?>" id="yield<?php echo $i;?>" value="Good"<?php echo($row_status['yield']=='Good')?'checked':'';?> >G
							<input type="radio" name="yield<?php echo $i;?>" id="yield<?php echo $i;?>" value="Satisfactory"<?php echo($row_status['yield']=='Satisfactory')?'checked':'';?>>S
	                  <input type="radio" name="yield<?php echo $i;?>" id="yield<?php echo $i;?>" value="Poor"<?php echo($row_status['yield']=='Poor')?'checked':'';?>>P</font>					  </td>
						<td width="143" align="center">
							<font style="font-size: 8.5pt" face="Arial" color="#000000">
							<input type="radio" name="seasonal_flunctuation<?php echo $i;?>" id=                            "seasonal_flunctuation<?php echo $i;?>" value="No Change"<?php echo($row_status['seasonal_fluctuation']=='No Change')?'checked':'';?> >N 
							<input type="radio" name="seasonal_flunctuation<?php echo $i;?>" id=                            "seasonal_flunctuation<?php echo $i;?>" value="Slight Change"<?php echo($row_status['seasonal_fluctuation']=='Slight Change')?'checked':'';?>>S
			  			  <input type="radio" name="seasonal_flunctuation<?php echo $i;?>" id=                            "seasonal_flunctuation<?php echo $i;?>" value="Drastic Change"<?php echo($row_status['seasonal_fluctuation']=='Drastic Change')?'checked':'';?>>D</font>					  </td>
						<td width="120" align="center">
		  			  <input type="text" name="water_table_fluctuation_min<?php echo $i;?>" id=                            "water_table_fluctuation_min<?php echo $i;?>" size="20" class="txt6" onBlur="float(this)" value="<?php echo $row_status['water_table_min'];?>"></td>
						<td width="134" align="center">
		  			  <input type="text" name="water_table_fluctuation_max<?php echo $i;?>" id=                            "water_table_fluctuation_max<?php echo $i;?>" size="20" class="txt6" onBlur="float(this)" value="<?php echo $row_status['water_table_max'];?>"></td>
					
					</tr></table></div></td>
			  	  <tr>
					  		<td></td>
					  		<td></td>
							<td></td>
					  		<td colspan="2"><div id="nf<?php echo $i;?>" class="hideme">
							<table border="0" width="100%" id="table16" cellpadding="0">
							<tr>
								<td colspan="3" align="center" bgcolor="#CCCCCC">
									<font style="font-size: 8.5pt; font-style: normal" face="Verdana"                                	color="#990000">Repairable Status</font>								</td>
								<td width="109" rowspan="2" align="center" bgcolor="#CCCCCC"> 
									<font style="font-size: 8.5pt; font-style:normal" face="Verdana" color="#990000">Remarks (State means to repair &amp; rejuvenate)</font></td>
							  <tr>
									<td align="center" width="61" bgcolor="#CCCCCC">
									<font style="font-size: 8.5pt; font-style: normal" face="Verdana" 				                                    color="#990000">Repairable</font></td>
								<td align="center" width="61" bgcolor="#CCCCCC">
									<font style="font-size: 8.5pt; font-style: normal" face="Verdana"                                    color="#990000">Non Repairable</font>					  			</td>
								<td align="center" width="64" bgcolor="#CCCCCC">
									<font style="font-size: 8.5pt; font-style: normal" face="Verdana"                                    color="#990000">Abandoned</font></td>
							  </tr>
							<tr>
								<td align="center" width="61" bgcolor="#CCCCCC">
									<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  			  <input type="radio" name="repairable_status<?php echo $i;?>" id=                                    "repairable_status<?php echo $i;?>" value="Repairable"<?php echo($row_status['repairable_status']=='Repairable')?'checked':'';?>></font>				  			  </td>
								<td align="center" width="61" bgcolor="#CCCCCC">
									<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  			  <input type="radio" name="repairable_status<?php echo $i;?>" id=                            		"repairable_status<?php echo $i;?>" value="Non Repairable"<?php echo($row_status['repairable_status']=='Non Repairable')?'checked':'';?>></font>				  			  </td>
								<td align="center" width="64" bgcolor="#CCCCCC">
									<font style="font-size: 8.5pt" face="Arial" color="#000000">
		  			  			  <input type="radio" name="repairable_status<?php echo $i;?>" id=                           			 "repairable_status<?php echo $i;?>" value="Abondoned"<?php echo($row_status['repairable_status']=='Abondoned')?'checked':'';?>></font>				  			  </td>
								<td width="109" align="center" bgcolor="#CCCCCC">
		       		  				<input type="text" name="remarks<?php echo $i;?>" id="remarks<?php echo $i;?>" size="40" style="font-size: 8pt; font-family: Verdana" class="txt5" value="<?php echo $row_status['remark'];?>">							  </td>
							</tr>
							</table>
							</div></td>
					  		<td></td>
					  		<td></td>
					  		<td></td>
					  		<td></td>
					  		<td></td>
					  		<td></td>
			  	  </tr>
					<?php
					
					$i++;
					 //} 
					//$j++;
					//$i++;
					//}
					}
					?>
					<input type="hidden" name="loccount" id="loccount" value="<?php echo $i;?>">
			  </table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>
				<font style="font-size: 8.5pt" face="Arial" color="#000000">
			    &nbsp;&nbsp;Legends:</font><ul type="DISC">
				<li><font style="font-size: 8.5pt" face="Arial" color="#000000">
				Functional status:&nbsp; &nbsp;&nbsp;F - Functional, NF - Not Functional</font></li>
				<li><font style="font-size: 8.5pt" face="Arial" color="#000000">
				Operational Status:&nbsp; &nbsp;IU - In Use, OU - Out of Use</font></li>
				<li><font style="font-size: 8.5pt" face="Arial" color="#000000">
				Quality Status:&nbsp;&nbsp;P - Potable, NP - Not Potable</font></li>
				<li><font style="font-size: 8.5pt" face="Arial" color="#000000">
				Yield: &nbsp;&nbsp;&nbsp;G - Good, S - Satisfactory, P-Poor</font></li>
				<li><font style="font-size: 8.5pt" face="Arial" color="#000000">
				Seasonal Fluctuations: &nbsp;N - No Change, S - Slight Change, D - Drastic Change</font></li></ul>	
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
			
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>
				<p align="center">
				<input type="submit" value="Click for Continue" name="submit" style="font-size: 8pt; font-family: Verdana; border-style: solid; border-width: 1px; font-weight:bold; background:#666666; color:#FFFFFF; width:140px; height:30px">
			</td>
		</tr>
	</table>
</form>
</div>


</body>
</html>